package tx.algoritmiek.week2;

public class SplitNode extends Node {

	private Node leftChild, rightChild;
	
	private double[] lowerArray = new double[GameObject.DIMENSION];
    private double[] upperArray = new double[GameObject.DIMENSION];

	public SplitNode(SplitNode parent) {
		super(parent);
	}

	public Node getLeftChild() {
		return leftChild;
	}

	public void setLeftChild(Node leftChild) {
		this.leftChild = leftChild;
	}

	public Node getRightChild() {
		return rightChild;
	}

	public void setRightChild(Node rightChild) {
		this.rightChild = rightChild;
	}

    @Override
    public double getLowerBound(int index) {
        return lowerArray[index];
    }

    @Override
    public double getUpperBound(int index) {
        return upperArray[index];
    }
    
    public void setBoundArrays(int index) {
        if(index <= 1) {
            double leftLower = this.leftChild.getLowerBound(index);
            double rightLower = this.rightChild.getLowerBound(index);
            if(leftLower <= rightLower) {
                this.lowerArray[index] = leftLower;
            } else {
                this.lowerArray[index] = rightLower;
            }
            
            double leftUpper = this.leftChild.getUpperBound(index);
            double rightUpper = this.rightChild.getUpperBound(index);
            if(leftUpper >= rightUpper) {
                this.upperArray[index] = leftUpper;
            } else {
                this.upperArray[index] = rightUpper;
            }
            
            this.setBoundArrays(index+1);
        }
    }
}
